home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / sozo2 / scsrc20.lzh / JAS.LZH / JAS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-22  |  3.4 KB  |  174 lines

  1. /*
  2.  * Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Joseph M Treat
  3.  *
  4.  * Permission is granted to anyone to use this software for any purpose
  5.  * on any computer system, and to redistribute it freely, with the
  6.  * following restrictions:
  7.  * 1) No charge may be made other than reasonable charges for reproduction.
  8.  * 2) Modified versions must be clearly marked as such.
  9.  * 3) The authors are not responsible for any harmful consequences
  10.  *    of using this software, even if they result from defects in it.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15.  
  16. #include <setjmp.h>
  17.  
  18. /* i don't know why we need this ...
  19. #define short int
  20. ... */
  21.  
  22. typedef struct _sym {
  23.     struct _sym *next;
  24.     union {
  25.         char here[8];
  26.         long stix[2];
  27.     } name;
  28.     long value;
  29.     unsigned short index;
  30.     unsigned short flags;
  31.     unsigned short access;
  32. } SYM;
  33.  
  34. typedef struct {
  35.     struct _sym *psym;
  36.     long value;
  37. } EXPR;
  38.  
  39. /*
  40.  * Flags for symbols
  41.  */
  42. #define UNK    0x0000
  43. #define BSS    0x0100
  44. #define TXT    0x0200
  45. #define DAT    0x0400
  46. #define SEGMT    0x0700
  47. #define EXTERN    0x0800
  48. #define GLOBAL    0x2000
  49. #define EQUATED    0x4000
  50. #define DEFINED    0x8000
  51.  
  52. #define NAMEX    (EQUATED|TXT)    /* special mark for name extension */
  53. #define NAMEV    0x87654321    /* special value for name extension */
  54.  
  55. typedef struct {
  56.     unsigned short mode;
  57.     unsigned char reg, inx;
  58.     EXPR expr;
  59. } OPERAND;
  60.  
  61. typedef struct {
  62.     char mnemon[8];
  63.     unsigned short op0, op1;
  64.     char size;
  65.     char format[14];
  66.     unsigned char flags;
  67. } INST;
  68.  
  69. typedef struct {
  70.     INST *inst;
  71.     OPERAND *op0, *op1;
  72.     short misc;
  73. } STMT;
  74.  
  75. /*
  76.  * Flags for operand types
  77.  */
  78. #define O_NONE    0x0000
  79. #define O_AN    0x0001
  80. #define O_DN    0x0002
  81. #define    O_INDR    0x0004
  82. #define O_DISP    0x0008
  83. #define O_POST    0x0010
  84. #define O_PRE    0x0020
  85. #define O_INDX    0x0040
  86. #define O_ABS    0x0080
  87. #define O_SABS    0x8000
  88. #define    O_PCRL    0x0100
  89. #define O_PCIX    0x0200
  90. #define O_IMM    0x0400
  91. #define O_USP    0x0800
  92. #define O_CCR    0x1000
  93. #define O_SR    0x2000
  94. #define O_REGS    0x4003
  95. #define O_ALL    0x87ff
  96. #define O_DMEM    0x80fc
  97. #define O_DST    0x80fe
  98. #define O_MEM    0x83fc
  99. #define O_LAB    0x8380
  100. #define O_STAT    0x83cc
  101. #define O_WRT    0x80ec
  102. #define O_RD    0x83dc
  103. #define O_NAN    0x87fe
  104.  
  105. /*
  106.  * Flags for the size field
  107.  */
  108. #define S_B    0x01
  109. #define S_W    0x02
  110. #define S_L    0x04
  111. #define S_BW    S_B|S_W
  112. #define S_BL    S_B|S_L
  113. #define S_WL    S_W|S_L
  114. #define S_BWL    S_B|S_W|S_L
  115.  
  116. /*
  117.  * Flags for special actions and defaults
  118.  */
  119. #define F_B    0x01
  120. #define F_W    0x02
  121. #define F_L    0x04
  122. #define F_TXT    0x08
  123. #define F_Q    0x10
  124. #define F_TV    0x20
  125. #define F_MQ    0x40
  126. #define F_PC    0x80
  127.  
  128. typedef struct _list {
  129.     struct _list *next;
  130.     union {
  131.         SYM *sym;
  132.         EXPR val;
  133.     } u;
  134. } LIST;
  135.  
  136. /*
  137.  * Types of things that get generated
  138.  */
  139. #define GENSTMT  1
  140. #define GENVALUE 2
  141. #define GENRELOC 3
  142. #define GENPCREL 4
  143. #define GENBRNCH 5
  144.  
  145. #define CBLEN 512
  146.  
  147. typedef struct {
  148.     unsigned char nbits;
  149.     unsigned char action;
  150.     int line;
  151.     EXPR value;
  152. } CBUF;
  153.  
  154. typedef struct _clist {
  155.     struct _clist *next;
  156.     short cnt, inx;
  157.     CBUF cblock[CBLEN];
  158. } CLIST;
  159.  
  160. typedef struct _branch BRANCH;
  161. struct _branch {
  162.     long where;
  163.     CBUF *cptr;
  164.     BRANCH *link;
  165. };
  166.  
  167. #define ALLOC(n,t) ((t *) allocate( (unsigned) ( (n) * sizeof (t) ) ))
  168. #define ALLO(t)    ALLOC(1,t)
  169. #define REALLO(p,n,t) ((t *) myreallocate( p, (unsigned) ( (n) * sizeof (t) ) ))
  170. #define STRCPY(s) strcpy( ALLOC(1+strlen(s),char), s )
  171. extern char *allocate(), *strcpy(), *myreallocate();
  172.  
  173. #define free my_free
  174.